#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<errno.h>
#include<netdb.h>
#include<netinet/in.h>
#include<arpa/inet.h>

#define DEFAULTPORT         2014
#define DEFAULT_BACKLOG     20
int main(int argc ,char *argv[])
{
    struct sockaddr_in socket_addr;
    struct hostent *host;

    if (argc < 2) {
        fprintf(stderr,"Please enter what you want to send !\n");
        exit(1);
    }

    if((host=gethostbyname("127.0.0.1")) == NULL) {
        herror("gethostbyname error !");
        exit(1);
    }

    socket_addr.sin_family = AF_INET;
    socket_addr.sin_port = htons(DEFAULTPORT);
    socket_addr.sin_addr = *((struct in_addr *)host->h_addr);
    bzero(&(socket_addr.sin_zero), 8);

    int socket_fd = socket(PF_INET, SOCK_STREAM, 0);
    if (socket_fd == -1)
        printf("Socket Error log is : %s\n", strerror(errno));

    if (connect(socket_fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr)) == -1) {
        perror("connect error !");
    }
    if (send(socket_fd, argv[1], 40, 0) == -1){
        perror("send error !");
        close(socket_fd);
    }

        return 0;
}
